#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
主题: 跳过可迭代对象的开始部分
问题: 你想遍历一个可迭代对象，但是它开始的某些元素你并不感兴趣，想跳过它们。
提示 : 
"""

def recipe1():
    from itertools import dropwhile
    with open('../hosts.txt') as f:
        for line in dropwhile(lambda line: line.startswith('#'), f):
            print(line, end='')

def recipe2():
    from itertools import islice
    items = ['a', 'b', 'c', 1, 4, 10, 15]
    for x in islice(items, 3, None):
        print(f"{x = }")

def recipe3():
    with open('../hosts.txt') as f:
        lines = (line for line in f if not line.startswith('#'))
        for line in lines:
            print(line, end='')

def main():
    print('recipe1'.center(20, '*'))
    recipe1() 
    print('recipe2'.center(20, '*'))
    recipe2() 
    print('recipe3'.center(20, '*'))
    recipe3() 

if __name__ == '__main__':
    main()         